import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] arr = {3,2,4,1,5};
//        Arrays.sort(arr);
//        mySort(arr);
        arraysSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void mySort(int[] arr){
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
    }
    public static void arraysSort(int[] arr){
        for (int i = 0,j=i;j<arr.length -1;  j = ++i ){
            int temp = arr[j+1];
            while (arr[j] > temp){
                arr[j+1]=  arr[j];
                if(j-- == 0){
                    break;
                }
            }
            arr[j+1] = temp;
        }
    }
}
